<template>
	<layout>
		<h4 class="title">当前周数</h4>
		<el-button class="button" :type="curbtn===id?'':'success'" v-for="id in maxbtn" :key="id" @click="curbtn=id; select(id);">{{ id }}</el-button>
		<el-table :data="tableData" border style="width: 100%" v-loading="loading" element-loading-text="拼命加载中">
		    <el-table-column
		    prop="verse"
		    label="" width="80">
		    </el-table-column>
		    <el-table-column
		    prop="K1"
		    label="星期一">
		    </el-table-column>
		    <el-table-column
		    prop="K2"
		    label="星期二">
		    </el-table-column>
		    <el-table-column
		    prop="K3"
		    label="星期三">
		    </el-table-column>
		    <el-table-column
		    prop="K4"
		    label="星期四">
		    </el-table-column>
		    <el-table-column
		    prop="K5"
		    label="星期五">
		    </el-table-column>
  		</el-table>
  </layout>
</template>

<script>
import Layout from './layout.vue'
let _ = require('lodash');
	export default {
		data () {
			return {
				maxbtn: 17,
				curbtn: 1,
				loading: true,
				tableData: [],
				datas: []
			}
		},
		components: {
			Layout
		},
		mounted() {
		
				let vm = this;
				vm.$axios.get('/api/hh/getKB',{
					params:{
						xn: '2016',
						xq: '1',
						dm: '0000356'
					},
					method: 'get'
				}).then(res => {
					if(res.data.errorCode != "0"){
						vm.$message.error('数据请求失败');
						return ;
					}
					vm.datas = res.data.obj;
					vm.filterData(vm.datas,1);
					vm.loading = false;
				});

		},
		methods: {
			select(obj){
				this.filterData(this.datas,obj);
			},
			filterData(data,n){
				this.tableData = [];
				_(4).times(i => {
					let obj = {};
					obj.verse = '第' + (i + 1) + '节'
 					_(5).times(j => {
						let k = 'K' + (j + 1);
						let l = k + (i + 1);
						obj[k] = data.filter(o => {
							if(o.jcz.startsWith(l)){
								let arr = o.analyse.split(',').map(ob => parseInt(ob));
								for(let m = 0; m < arr.length; m++){
									if(arr[m] == n) return o;
								}
							}
							return ;
						}).map(o => {
							return o.zwmc + '-' + o.bjmc + ',' + o.stimezc + '周';
						}).join('');
					});
					this.tableData.push(obj);
				});
			},

		}
	}
</script>

<style scoped>
.title{
	margin-bottom: 18px;
}
.button{
	width: 50px;
	margin-bottom: 18px;
}
</style>